package com.inifitness.common.exceptions;

import com.inifitness.common.result.ResultCode;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常
 *
 * @author sunjinfeng
 * @version 1.0.0
 * @since 2024/04/18 11:00:00
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BizException extends RuntimeException {

  private final ResultCode resultCode;
  /**
   * 错误码
   */
  private final String code;

  /**
   * 错误信息
   */
  private final String errorMsg;

  public BizException(ResultCode resultCode) {
    super("{code:" + resultCode.getCode() + ",errorMsg:" + resultCode.getMsg() + "}");
    this.resultCode = resultCode;
    this.code = resultCode.getCode();
    this.errorMsg = resultCode.getMsg();
  }

  public BizException(ResultCode resultCode,Throwable throwable) {
    super("{code:" + resultCode.getCode() + ",errorMsg:" + resultCode.getMsg() + "}",throwable);
    this.resultCode = resultCode;
    this.code = resultCode.getCode();
    this.errorMsg = resultCode.getMsg();
  }
}
